﻿using System;
using Dataweb.NShape;
using Dataweb.NShape.Advanced;
using System.Drawing;

namespace cz.zcu.PreSti.Shapes
{
    public abstract class GeneratorSymbol : CircleBase, ISymbol
    {

        protected override Rectangle CalculateBoundingRectangle(bool tight)
        {
            return base.CalculateBoundingRectangle(true);
        }


        protected override bool CalculatePath()
        {
            if (base.CalculatePath())
            {
                Path.Reset();
                float left = -Diameter / 2f;
                float top = -Diameter / 2f;
                float bottom = top + Diameter;
                Path.StartFigure();
                Path.AddEllipse(left, top, Diameter, Diameter);
                Path.AddCurve(new PointF[] { new PointF(-4, bottom), new PointF(0, bottom - 4), new PointF(4, bottom)}, 1);
                Path.CloseFigure();
                return true;
            }
            else return false;
        }

        public override bool HasControlPointCapability(ControlPointId controlPointId, ControlPointCapabilities controlPointCapability)
        {
            switch (controlPointId)
            {
                case 1:
                    return ((controlPointCapability & ControlPointCapabilities.Connect) != 0);
                default:
                    return base.HasControlPointCapability(controlPointId, controlPointCapability);
            }
        }


        protected override int ControlPointCount
        {
            get { return ActionsCount + EventsCount + SettersCount + GettersCount; }
        }

        protected override void CalcControlPoints()
        {
            int top = (int)Math.Round(-Diameter / 2f);
            int bottom = top + Diameter;

            ControlPoints[0].X = 0;
            ControlPoints[0].Y = bottom;
        }

        protected internal GeneratorSymbol(ShapeType shapeType, Template template)
            : base(shapeType, template)
        {
        }


        protected internal GeneratorSymbol(ShapeType shapeType, IStyleSet styleSet)
            : base(shapeType, styleSet)
        {
        }

        public override void Draw(Graphics graphics)
        {
            base.Draw(graphics);
            DrawIcon(graphics);
        }

        protected abstract void DrawIcon(Graphics graphic);

        #region ISymbol Members

        public abstract BaseComponent initializeComponent(IPresentation p);

        public virtual int ActionsCount
        {
            get { return 0; }
        }

        public virtual int EventsCount
        {
            get { return 0; }
        }

        public virtual int SettersCount
        {
            get { return 0; }
        }

        public virtual int GettersCount
        {
            get { return 1; }
        }

        public virtual string GetTitleForAction(int id)
        {
            return null;
        }

        public virtual string GetTitleForEvent(int id)
        {
            return null;
        }

        public virtual string GetTitleForSetter(int id)
        {
            return null;
        }

        public virtual string GetTitleForGetter(int id)
        {
            switch (id)
            {
                case 0:
                    return "Generated value";
            }
            return null;
        }

        #endregion
    }
}
